<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">

		<%include("/common/include.html"){}%>
	</head>

	<body class="easyui-layout">
			<table id="dailyTotal_datagrid" class="easyui-datagrid" style="height:100%;">
		
			</table>
			<div id="productGXC_tb" >
			
				<label class="label-top" style="width: 100%; display: block;">日期</label>
				<input  id="dailySaleTotal_datebox" name="month"  class="easyui-datebox theme-textbox-radius"style="height: 32px; width: 212px; text-align: center" />
			
				<input name="organIds" id="organIds" type="hidden" value="${organization.ids! }">
			</div>
			
		
		<script type="text/javascript">
			$(document).ready(function () {
				dateFormatter();
				//加载数据表格
				loadTable();
				$('#dailySaleTotal_datebox').datebox({
					onChange: function(date){
						loadTable();
					}
				});
			});
			
			function  loadTable()
			{	
				var columnsAll1 = new Array();
				columnsAll1.push({field:'a+b',title:'(A+B)表',colspan:15,align:'center'});
				columnsAll1.push({field:'a',title:'A表(当年新顾客)',colspan:5,align:'center'});
				var columnsAll = new Array();
				columnsAll.push({field:'ids',title:'ids',align:'center',hidden:true});
				columnsAll.push({field:'date',title:'日期',align:'center'});
				columnsAll.push({field:'sddrs',title:'到店人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'dcrs',title:'掉秤人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'dcjs',title:'掉秤斤数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'zcrs',title:'涨称人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'zcjs',title:'涨称斤数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'pcrs',title:'平称人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'zjz',title:'总减重',align:'center',
					formatter: function(value,row,index)
					{	
						var dcjs = parseFloat(0);
						var zcjs = parseFloat(0);
						if(row.dcjs!=null && row.dcjs!=""){
							dcjs = parseFloat(row.dcjs);
						}
						
						if(row.zcjs!=null && row.zcjs!=""){
							zcjs = parseFloat(row.zcjs);
						}
							if(parseFloat(dcjs-zcjs) == '0'){
								return "";
							}else{
								return   parseFloat(dcjs-zcjs).toFixed(1);
							}
							
							
					}
					
				});

				columnsAll.push({field:'sycprs',title:'精护人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0.0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'ggrs',title:'巩固人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'cjrs',title:'当日<br/>成交<br/>顾客',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'dbrs',title:'当日<br/>达标<br/>顾客',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'rjdccc',title:'人均<br/>掉秤',align:'center',
					formatter: function(value,row,index)
					{	
						if(value!=null){
							return value;
						}else{
						var zjz = parseFloat(0);
						var dcjs = parseFloat(0);
						var zcjs = parseFloat(0);
						if(row.dcjs!=null && row.dcjs!=""){
							dcjs = parseFloat(row.dcjs);
						}
						
						if(row.zcjs!=null && row.zcjs!=""){
							zcjs = parseFloat(row.zcjs);
						}
							
						zjz =  parseFloat(dcjs-zcjs).toFixed(1);
					
						
						var ggrs = parseFloat(0);
						var sddrs = parseFloat(0);
						
						if(row.zjz!=null && row.zjz!=""){
							zjz = parseFloat(row.zjz);
						}
						
						if(row.ggrs!=null && row.ggrs!=""){
							ggrs = parseFloat(row.ggrs);
						}
						
						if(row.sddrs!=null && row.sddrs!=""){
							sddrs = parseFloat(row.sddrs);
						}
						var rjdc =0;
						if((sddrs-ggrs)!=0){
							rjdc = zjz/(sddrs-ggrs);
							
						}
						
						if(rjdc == "0"){
							return ""
						}else{
							return  rjdc.toFixed(1);
						}
							
						}
					}
				});
				columnsAll.push({field:'dczb',title:'掉秤<br/>占比',align:'center',
					formatter: function(value,row,index)
					{	
						var dcrs =  parseFloat(0);
						var ggrs =  parseFloat(0);
						var sddrs =  parseFloat(0);
						if(row.sddrs!=null && row.sddrs!=""){
							sddrs = parseFloat(row.sddrs);
						}
						if(row.dcrs!=null && row.dcrs!=""){
							dcrs = parseFloat(row.dcrs);
						}
						if(row.ggrs!=null && row.ggrs!=""){
							ggrs = parseFloat(row.ggrs);
						}
						 value = dcrs/(sddrs-ggrs)*100;
						 value = value.toFixed(2)+"%";
						return  value;
					}
				});
				columnsAll.push({field:'jhzb',title:'精护<br/>占比',align:'center',
					formatter: function(value,row,index)
					{	
						if(value!=null){
							return value;
						}else{
							var sycprs =   parseFloat(0);
							var sddrs = parseFloat(0);
							if(row.sddrs!=null && row.sddrs!=""){
								sddrs = parseFloat(row.sddrs);
							}
							if(row.sycprs!=null && row.sycprs!=""){
								sycprs = parseFloat(row.sycprs);
							}
							if(sddrs!=0){
							
								var value = parseFloat(sycprs)/sddrs*100;
								value = value.toFixed(2)+"%";
							}
							
							return  value;
						}
						
					}
				});
				columnsAll.push({field:'xgkddrs',title:'到店人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'xgkdcrs',title:'掉秤人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'xgksjdc',title:'掉秤斤数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				columnsAll.push({field:'xgkjhrs',title:'精护人数',align:'center',
					formatter: function(value,row,index)
					{	
						if(value == "0.0"){
							return  "";
						}else{
							return value;
						}
						
					}});
				
				var month = $("#dailySaleTotal_datebox").val();
				var organIds = $("#organIds").val();
				
				
				$('#dailyTotal_datagrid').datagrid({
					cls: "theme-datagrid",
					toolbar: '#productGXC_tb',
					singleSelect:true,
					fitColumns:false,
					rownumbers: true,
				    columns:[columnsAll1,columnsAll],
				    url: "${cxt!}/dailyNursingTotal/getDailyTotal",
				    queryParams: {
						'month': month,
						'organIds':organIds
					},
				    onLoadSuccess:function(data){
				    	var n = data.total;
						 var rows = $('#dailyTotal_datagrid').datagrid('getRows');
						if(rows.length > 0){
							
							var hjddrs = compute_GXC('sddrs');
							var hjzjz = compute_GXC('zjz');
							var hjggrs = compute_GXC('ggrs');
							var hjdcrs = compute_GXC('dcrs');
							var hjsycprs = compute_GXC('sycprs');
							var xgkddrs = compute_GXC('xgkddrs');
							var xgkdcrs = compute_GXC('xgkdcrs');
							var xgksjdc =  compute_GXC('xgksjdc');
							var xgkjhrs = compute_GXC('xgkjhrs');
							var sddrs = compute_GXC('sddrs');
							var dcrs = compute_GXC('dcrs');
							var dcjs = compute_GXC('dcjs');
							var zcrs = compute_GXC('zcrs');
							var zcjs = compute_GXC('zcjs');
							var pcrs = compute_GXC('pcrs');
							var zjz = compute_GXC('zjz');
							var sycprs = compute_GXC('sycprs');
							var ggrs = compute_GXC('ggrs');
							var cjrs = compute_GXC('cjrs');
							var dbrs = compute_GXC('dbrs');
						
							
							var hjrjdc = 0;
							var hjdczb = 0;
							var hjsycprs = 0;
							if(hjddrs-hjggrs!= 0){
								hjrjdc = hjzjz/(parseFloat(hjddrs)-parseFloat(hjggrs)).toFixed(1);
								hjdczb = hjdcrs/(parseFloat(hjddrs)-parseFloat(hjggrs))*100;
								hjdczb = hjdczb.toFixed(2);
							}
							if(hjddrs!=0){
								hjsycprs = hjsycprs/hjddrs*100;
								hjsycprs = hjsycprs.toFixed(2);
							}
							$('#dailyTotal_datagrid').datagrid('insertRow', {
								index: 0,
								row: {date: '合计',
								sddrs:sddrs,
								dcrs:dcrs,
								dcjs:dcjs,
								zcrs:zcrs,
								zcjs:zcjs,
								pcrs:pcrs,
								zjz:zjz,
								sycprs:sycprs,
								ggrs:ggrs,
								cjrs:cjrs,
								dbrs:dbrs,
								rjdc:hjrjdc,
								dczb:hjdczb,
								sycprszb:hjsycprs,
								xgkddrs:xgkddrs,
								xgkdcrs:xgkdcrs,
								xgksjdc: xgksjdc,
								xgkjhrs:xgkjhrs
								}
				             });
							
							
							$('#dailyTotal_datagrid').datagrid('insertRow', {
								index: 1,
								row: {date: '日均',
								sddrs:(sddrs/n).toFixed(1),
								dcrs:(dcrs/n).toFixed(1),
								dcjs:(dcjs/n).toFixed(1),
								zcrs:(zcrs/n).toFixed(1),
								zcjs:(zcjs/n).toFixed(1),
								pcrs:(pcrs/n).toFixed(1),
								zjz:(zjz/n).toFixed(1),
								sycprs:(sycprs/n).toFixed(1),
								ggrs:(ggrs/n).toFixed(1),
								cjrs:(cjrs/n).toFixed(1),
								dbrs:(dbrs/n).toFixed(1),
								rjdc:hjrjdc,
								dczb:hjdczb,
								sycprszb:hjsycprs,
								xgkddrs:(xgkddrs/n).toFixed(1),
								xgkdcrs:(xgkdcrs/n).toFixed(1),
								xgksjdc:( xgksjdc/n).toFixed(1),
								xgkjhrs:(xgkjhrs/n).toFixed(1)
								}
				             });
					
					
						} 
					}
				});
			}
			
			function  dateFormatter(){
				$('#dailySaleTotal_datebox').datebox({
				       //显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
				       onShowPanel: function () {
				          //触发click事件弹出月份层
				          span.trigger('click'); 
				          if (!tds)
				            //延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
				            setTimeout(function() { 
				                tds = p.find('div.calendar-menu-month-inner td');
				                tds.click(function(e) {
				                   //禁止冒泡执行easyui给月份绑定的事件
				                   e.stopPropagation(); 
				                   //得到年份
				                   var year = /\d{4}/.exec(span.html())[0] ,
				                   //月份
				                   //之前是这样的month = parseInt($(this).attr('abbr'), 10) + 1; 
				                   month = parseInt($(this).attr('abbr'), 10);  

							         //隐藏日期对象                     
							         $('#dailySaleTotal_datebox').datebox('hidePanel').datebox('setValue', year + '-' + month); 
				                 });
				             }, 0);
				        },
				            //配置parser，返回选择的日期
				            parser: function (s) {
				                if (!s) return new Date();
				                var arr = s.split('-');
				                return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
				            },
				            //配置formatter，只返回年月 之前是这样的d.getFullYear() + '-' +(d.getMonth()); 
				            formatter: function (d) { 
				                var currentMonth = (d.getMonth()+1);
				                var currentMonthStr = currentMonth < 10 ? ('0' + currentMonth) : (currentMonth + '');
				                return d.getFullYear() + '-' + currentMonthStr; 
				            }
				        });

				        //日期选择对象
				        var p = $('#dailySaleTotal_datebox').datebox('panel'), 
				        //日期选择对象中月份
				        tds = false, 
				        //显示月份层的触发控件
				        span = p.find('span.calendar-text'); 
				        var curr_time = new Date();

				        //设置前当月
				        $("#dailySaleTotal_datebox").datebox("setValue", myformatter(curr_time));
			    
			 
			}
			//格式化日期
			function myformatter(date) {
			    //获取年份
			    var y = date.getFullYear();
			    //获取月份
			    var m = date.getMonth() + 1;
			    return y + '-' + m;
			}

			//指定列求和
			function compute_GXC(colName) {
			     var rows = $('#dailyTotal_datagrid').datagrid('getRows');
			     var total = 0;
			     for (var i = 0; i < rows.length; i++) {
			    	 if(typeof(rows[i][colName]) != 'undefined'){
			    		 total += parseFloat(rows[i][colName]);
			    	 }
			     }
			     if(total > 0){
			    	 return total.toFixed(1);
			     }else{
			    	 return 0;
			     }
			}

		</script>
	</body>
</html>